<?php
class webController extends appController{
    
    public function getOption()
    {
        $m = Model('rchat');
        $cfg = $m->get_cfg();
        $time = yf_time();
        $m->updateFrontTime($cfg['frontTime']);
        $option['timestamp'] = intval($cfg['timestamp'])+intval($cfg['frontTime']);
        $option['refreshtime'] = intval($cfg['refreshtime']);
        $option['commentDayMax'] = intval($cfg['commentDayMax']);
        $option['commentMinuteMax'] = intval($cfg['commentMinuteMax']);
        $option['chatMaxNum'] = intval($cfg['chatMaxNum']);
        $option['now'] = $time;
        $wxid = intval($_GET['wxid']);
        if($wxid>0){
            $option['commentDayNum'] = $m->get_comment_num($wxid);
        }else{
            $option['commentDayNum'] = 0;
        }
        
        die($_REQUEST['callback']."(".json_encode($option).")");
        
    }
    public function getChatJson()
    {
        $data = file_get_contents(ROOT_PATH."chatR.json");
        die($_REQUEST['callback']."(".json_encode($data).")");
    }
    /**
     * 保存评论
     * @return text
     */
    public function saveComment(){
        $res = array("error"=> 0,"content"=>"");
        $wxid = intval($_GET['wxid']);
        if(!$wxid>0){
            $res['content'] = "用户未登录，请登录后方可吐槽";
            die($_REQUEST['callback']."(".json_encode($res).")");
        }
        $data['comment'] = $_GET['text'];
        $data['wxid'] = $wxid;
        $data['status'] =0;
        $res =Model("rchat")->create_record($data);
        die($_REQUEST['callback']."(".json_encode($res).")");
    }
    
    
}